<script>
	import http from "utils/http.js"
	export default {
		globalData:{
			user:null,
			platform:5
		},
		onLaunch: function() {
			console.log('App Launch')
			if (!wx.cloud) {
				console.error('请使用 2.2.3 或以上的基础库以使用云能力')
			} else {
				wx.cloud.init({
					env: 'qshp-4gq4fr6hd34bacff',
					traceUser: true,
				})
			}
			let that = this
			uni.getStorage({
				key: 'uni_user_data',
				success: function(res) {
					var data = res.data;
					that.globalData.user = data
					if(data != null){
						//#ifdef MP-WEIXIN
						wx.cloud.callFunction({
							name: 'setOpenId',
							data: {
								uid: data.uid + ""
							}
						}).then(res => {
						
						})
						//#endif
					}
				}
			});
			uni.getSystemInfo({
				success: (res) => {
					if(res.platform == "ios"){
						that.globalData.platform = 5
					}else{
						that.globalData.platform = 4
					}
				},
			});
		},
		onTabItemTap(e) {
			console.log(e)
			if(e.index > 0){
				if(getApp().globalData.user == null){
					uni.navigateTo({
						url:"pages/login/login"
					})
				}
			}
		},
		onShow: function() {
			this.loadMessageData();
		},

		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			loadMessageData: function() {
				http.request("message/heart", {}, {
					success: function(data) {
						var replyInfo = data.body.replyInfo.count;
						var pmInfos = data.body.pmInfos.length;
						if (replyInfo > 0) {
							uni.setTabBarBadge({
								index: 2,
								text: replyInfo + ""
							})
						} else {
							uni.removeTabBarBadge({
								index:2
							})
						}
						if (pmInfos > 0) {
							uni.setTabBarBadge({
								index: 3,
								text: pmInfos + ""
							})
						} else {
							uni.removeTabBarBadge({
								index:3
							})
						}

					},
					fail: function() {}
				}, false)
			}
		}

	}
</script>

<style>
	/*每个页面公共css */
	button {
		background: initial;
		padding: 0px;
		line-height: 30rpx;
	}
	
	button:focus {
		outline: 0;
	}
	
	button::after {
		border: none;
	}
	
	.btn_hover {
		opacity: true;
	}
	
	.container {
		display: flex;
		flex-direction: column;
		width: 100vw;
		padding-bottom: 0;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
	}
	
	.column-content {
		display: flex;
		flex-direction: column;
	}
	
	.parent-content {
		display: flex;
		width: 100%;
	}
	
	.row-content {
		display: flex;
		flex-direction: row;
	}
	
	.row-reverse-content{
		display: flex;
		flex-direction: row-reverse;
	}
	
	.justify-center-content {
		justify-content: center;
	}
	
	.align-items-center-content {
		align-items: center;
	}
	
	.flex-grow-content {
		display: flex;
		flex-grow: 1;
	}
	
	.grid-content {
		display: flex;
		flex-direction: row;
		flex-flow: wrap;
		align-content: flex-start;
	}
	
	.app-card {
		box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
		transition: 0.3s;
		border-radius: 10rpx;
		background-color: #fff;
	}
	
	.app-card:hover {
		box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
	}
	
	.app-arrow-icon {
		width: 30rpx;
		height: 30rpx;
		margin-right: 20rpx;
		min-width: 30rpx;
	}
	
	.app-add-button {
		display: flex;
		margin-left: 30rpx;
		margin-right: 30rpx;
		margin-top: 30rpx;
		margin-bottom: 20rpx;
		height: 100rpx;
		border-radius: 8rpx;
		background-color: #173c6f;
		color: #fff;
		font-size: 28rpx;
		font-weight: bold;
		align-items: center;
		justify-content: center;
	}
	
	.submit_button {
		display: flex;
		color: #fff;
		font-size: 17px;
		font-weight: bold;
		align-items: center;
		justify-content: center;
		border-radius: 30px;
		height: 60px;
		position: fixed;
		bottom: 50px;
		left: 15px;
		right: 15px;
		z-index: 1000;
		cursor: pointer;
	}
	
	.app_title_color {
		color: #333333;
	}
	.app_subtitle_color {
		color: #aaaaaa;
	}
	.app_background_color{
		background-color:#eeeeee;
	}
	.app_content_color{
		background-color:#ffffff;
	}
	
	page {
		background-color:#eeeeee;
	}
	
	@media (prefers-color-scheme: dark) {
		.app_title_color {
			color: #cccccc;
		}
		.app_subtitle_color {
			color: #666666;
		}
		.app_background_color{
			background-color:#1a1a1a;
		}
		.app_content_color{
			background-color:#272727;
		}
		page {
			background-color:#1a1a1a;
		}
	}
	
</style>
